package com.sw.small_world.fragment.me.mycircle;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.sw.small_world.R;
import com.sw.small_world.activity.ClickButtonActivity;
import com.sw.small_world.fragment.base.BaseFragment;
import com.sw.small_world.utils.ConstantUtils;
import com.sw.small_world.widgets.CircleImageView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/16.
 */

public class MyCircleFragment extends BaseFragment {


    @Bind(R.id.list_view)
    ListView listView;
    @Bind(R.id.add_person)
    LinearLayout addPerson;
    private ClickButtonActivity activity;
    ArrayList<String> list = new ArrayList<>();
    private MyAdapter myAdapter;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (ClickButtonActivity) getActivity();
        setActionBar();
    }

    @Override
    protected Object requestData() {
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        return ConstantUtils.STATE_SUCCESSED;
    }

    @Override
    protected View getSuccessView() {
        View view = View.inflate(activity, R.layout.fragment_my_circle, null);
        ButterKnife.bind(this, view);
        myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);
        return view;
    }

    @Override
    public void onClick(View v) {

    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = View.inflate(activity, R.layout.item_my_circle, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            return convertView;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

    }

    private void setActionBar() {
        activity.tvTitle.setText("我的圈子");
//        activity.tvRight.setVisibility(View.VISIBLE);
//        activity.tvRight.setText("移除");
//        activity.tvRight.setOnClickListener(new View.OnCls-   ickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });
    }

    static class ViewHolder {
        @Bind(R.id.iv_portrait)
        CircleImageView ivPortrait;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_deep)
        TextView tvDeep;
        @Bind(R.id.tv_company_position)
        TextView tvCompanyPosition;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
